<!--
 * @Author: your name
 * @Date: 2021-04-21 14:31:15
 * @LastEditTime: 2021-04-21 14:49:24
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \vue03-demo\src\components\SuspenseWithErrror.vue
-->
<template>
  <slot v-if="error" name="error" :err="error"></slot>
  <Suspense v-else>
    <template #default>
      <slot name="default"></slot>
    </template>
    <template #fallback>
      <slot name="fallback"></slot>
    </template>
  </Suspense>
</template>

<script lang="ts">
import { defineComponent, ref, onErrorCaptured } from 'vue'

export default defineComponent({
  setup () {
    const error = ref('')
    onErrorCaptured(err => {
      error.value = err as string
      return true
    })
    return {
      error
    }
  }
})
</script>

<style>

</style>
